package com.tencreat.service.mall.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tencreat.common.core.domain.model.ReqIdParam;
import com.tencreat.common.core.domain.model.ReqIdsParam;
import com.tencreat.domain.mall.MallOrderGoods;
import com.tencreat.mapper.mall.MallOrderGoodsMapper;
import com.tencreat.service.mall.IMallOrderGoodsService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 订单商品Service业务层处理
 *
 * @author tencreat
 * @date 2021-08-13
 */
@Service
public class MallOrderGoodsServiceImpl extends ServiceImpl<MallOrderGoodsMapper, MallOrderGoods> implements IMallOrderGoodsService {


    /**
     * 查询订单商品
     *
     * @param id 订单商品ID
     * @return 订单商品
     */
    @Override
    public MallOrderGoods selectMallOrderGoodsById(ReqIdParam id) {
        return baseMapper.selectById(id.getId());
    }

    /**
     * 查询订单商品列表
     *
     * @param mallOrderGoods 订单商品
     * @return 订单商品
     */
    @Override
    public List<MallOrderGoods> selectMallOrderGoodsList(MallOrderGoods mallOrderGoods) {
        return baseMapper.selectList(Wrappers.query(mallOrderGoods));
    }

    /**
     * 新增订单商品
     *
     * @param mallOrderGoods 订单商品
     * @return 结果
     */
    @Override
    public int insertMallOrderGoods(MallOrderGoods mallOrderGoods) {
        mallOrderGoods.setCreateTime(LocalDateTime.now());
        return baseMapper.insert(mallOrderGoods);
    }

    /**
     * 修改订单商品
     *
     * @param mallOrderGoods 订单商品
     * @return 结果
     */
    @Override
    public int updateMallOrderGoods(MallOrderGoods mallOrderGoods) {
        mallOrderGoods.setUpdateTime(LocalDateTime.now());
        return baseMapper.updateById(mallOrderGoods);
    }

    /**
     * 批量删除订单商品
     *
     * @param ids 需要删除的订单商品ID
     * @return 结果
     */
    @Override
    public int deleteMallOrderGoodsByIds(ReqIdsParam ids) {
        return baseMapper.deleteBatchIds(ids.getId());
    }

    /**
     * 删除订单商品信息
     *
     * @param id 订单商品ID
     * @return 结果
     */
    @Override
    public int deleteMallOrderGoodsById(ReqIdParam id) {
        return baseMapper.deleteById(id.getId());
    }

    @Override
    public void updateOrderTypeByGoodsNorms(String orderSn, Long goodsId, Long normsId, int OrderStatus, LocalDateTime day) {
        baseMapper.updateOrderTypeByGoodsNorms(orderSn, goodsId, normsId, OrderStatus, day, LocalDateTime.now());
    }
}
